package me.shiqiang.im.msg;

import java.util.Arrays;

/**
 * @author cuishiqiang
 * @date 2017/12/5 下午8:02
 */
public class SndMsg {
    private Long localId;
    private Long from;
    private String fromName;
    private Long to;
    private Integer mType;
    private Integer cType;
    private Long[] at = new Long[0];
    private String msg;

    public SndMsg() {
    }

    public Long getLocalId() {
        return localId;
    }

    public void setLocalId(Long localId) {
        this.localId = localId;
    }

    public Long getFrom() {
        return from;
    }

    public void setFrom(Long from) {
        this.from = from;
    }

    public String getFromName() {
        return fromName;
    }

    public void setFromName(String fromName) {
        this.fromName = fromName;
    }

    public Long getTo() {
        return to;
    }

    public void setTo(Long to) {
        this.to = to;
    }

    public Integer getmType() {
        return mType;
    }

    public void setmType(Integer mType) {
        this.mType = mType;
    }

    public Integer getcType() {
        return cType;
    }

    public void setcType(Integer cType) {
        this.cType = cType;
    }

    public Long[] getAt() {
        return at;
    }

    public void setAt(Long[] at) {
        this.at = at;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    @Override
    public String toString() {
        final StringBuilder sb = new StringBuilder("{");
        sb.append("\"localId\":")
                .append(localId);
        sb.append(",\"from\":")
                .append(from);
        sb.append(",\"fromName\":\"")
                .append(fromName).append('\"');
        sb.append(",\"to\":")
                .append(to);
        sb.append(",\"mType\":")
                .append(mType);
        sb.append(",\"cType\":")
                .append(cType);
        sb.append(",\"at\":")
                .append(Arrays.toString(at));
        sb.append(",\"msg\":\"")
                .append(msg).append('\"');
        sb.append('}');
        return sb.toString();
    }

    public MsgBody newMsgBody(){
        return newMsgBody(null, 0);
    }

    public MsgBody newMsgBody(Long syncKey,int at){
        MsgBody body = new MsgBody();
        body.setcType(this.getcType());
        body.setFrom(this.getFrom());
        body.setTo(this.getTo());
        body.setLocalId(this.getLocalId());
        body.setMsg(this.getMsg());
        body.setmType(this.getmType());
        body.setSyncKey(syncKey);
        body.setAt(at);
        body.setTs(System.currentTimeMillis());
        body.setFromName(this.getFromName());
        return body;
    }


    public DistributeMsgBody newMsgBody(long syncKey) {
        DistributeMsgBody body = new DistributeMsgBody();
        body.setcType(this.getcType());
        body.setFrom(this.getFrom());
        body.setTo(this.getTo());
        body.setLocalId(this.getLocalId());
        body.setMsg(this.getMsg());
        body.setmType(this.getmType());
        body.setSyncKey(syncKey);
        body.setAt(this.getAt());
        body.setTs(System.currentTimeMillis());
        body.setFromName(this.getFromName());
        return body;
    }
}
